package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.hiultra.common.core.domain.entity.ArcCabinet;
import com.hiultra.common.core.domain.entity.ArcShelves;
import com.hiultra.common.core.domain.entity.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.service.IArcCabinetService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 智能柜Controller
 * 
 * @author 李爽
 * @date 2023-08-22
 */
@Api(tags="智能柜Controller")
@RestController
@RequestMapping("/base/cabinet")
public class ArcCabinetController extends BaseController
{
    @Autowired
    private IArcCabinetService arcCabinetService;

    /**
     * 查询智能柜列表
     */
    @ApiOperation(value = "查询智能柜列表", notes = "查询智能柜列表 ")
    @PreAuthorize("@ss.hasPermi('base:cabinet:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArcCabinet arcCabinet)
    {
        startPage();
        List<ArcCabinet> list = arcCabinetService.selectArcCabinetList(arcCabinet);
        return getDataTable(list);
    }

    /**
     * 导出智能柜列表
     */
    @ApiOperation(value = "导出智能柜列表", notes = "导出智能柜列表")
    @PreAuthorize("@ss.hasPermi('base:cabinet:export')")
    @Log(title = "智能柜", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcCabinet arcCabinet)
    {
        List<ArcCabinet> list = arcCabinetService.selectArcCabinetList(arcCabinet);
        ExcelUtil<ArcCabinet> util = new ExcelUtil<ArcCabinet>(ArcCabinet.class);
        util.exportExcel(response, list, "智能柜数据");
    }

    /**
     * 获取智能柜详细信息
     */
    @ApiOperation(value = "获取智能柜详细信息", notes = "获取智能柜详细信息")
    @PreAuthorize("@ss.hasPermi('base:cabinet:query')")
    @GetMapping(value = { "/", "/{cabinetId}" })
    public AjaxResult getInfo(@PathVariable(value = "cabinetId", required = false) Long cabinetId)
    {
        AjaxResult ajax = AjaxResult.success();
        ArcCabinet arcCabinet = arcCabinetService.selectArcCabinetByCabinetId(cabinetId);
        ajax.put(AjaxResult.DATA_TAG, arcCabinet);
        ajax.put("cabinets", arcCabinetService.selectArcCabinetAll());
        return ajax;
    }

    /**
     * 新增智能柜
     */
    @ApiOperation(value = "新增智能柜", notes = "新增智能柜")
    @PreAuthorize("@ss.hasPermi('base:cabinet:add')")
    @Log(title = "智能柜", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcCabinet arcCabinet)
    {
        return toAjax(arcCabinetService.insertArcCabinet(arcCabinet));
    }

    /**
     * 修改智能柜
     */
    @ApiOperation(value = "修改智能柜", notes = "修改智能柜")
    @PreAuthorize("@ss.hasPermi('base:cabinet:edit')")
    @Log(title = "智能柜", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcCabinet arcCabinet)
    {
        return toAjax(arcCabinetService.updateArcCabinet(arcCabinet));
    }

    /**
     * 删除智能柜
     */
    @ApiOperation(value = "删除智能柜", notes = "删除智能柜")
    @PreAuthorize("@ss.hasPermi('base:cabinet:remove')")
    @Log(title = "智能柜", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cabinetIds}")
    public AjaxResult remove(@PathVariable Long[] cabinetIds)
    {
        return toAjax(arcCabinetService.deleteArcCabinetByCabinetIds(cabinetIds));
    }

    /**
     * 设置智能柜规格
     */
    @ApiOperation(value = "设置智能柜规格", notes = "设置智能柜规格")
    //@PreAuthorize("@ss.hasPermi('base:cabinet:add')")
    @Log(title = "设置智能柜规格", businessType = BusinessType.INSERT)
    @PostMapping("/updateGridAndLayer")
    public AjaxResult updateGridAndLayer(@RequestBody ArcCabinet arcCabinet)
    {
        return toAjax(arcCabinetService.updateGridAndLayer(arcCabinet));
    }

    /**
     *获取智能柜下拉框数据
     */
    @GetMapping("/treeselectCabinet/{cabinetId}")
    @ApiOperation(value = "获取智能柜下拉框数据", notes = "获取智能柜下拉框数据")
    public AjaxResult treeselectCabinet(@PathVariable Long cabinetId)
    {
        List<ArcCabinet> cabinets = arcCabinetService.selectArcCabinetList(new ArcCabinet(){{setZcabinetId(cabinetId);}});
        return AjaxResult.success(arcCabinetService.buildCabinetTreeSelect(cabinets));
    }
}
